import time

from PyQt5.QtCore import QThread, pyqtSignal
import ShuDu


class Worker(QThread):
    trigger = pyqtSignal(object)

    def __init__(self):
        super(Worker, self).__init__()

        self.ShuDu = None
        self.x = []
        self.y = []
        self.t = None

    #
    def init(self, x, y, t=None):
        self.t = t
        self.x = x
        self.y = y

        if t == 'YF':
            self.y = y[::-1]
            t = []
            for i in x:
                t.append(i[::-1])
            self.x = t

        if t == 'XF':
            self.x = x[::-1]
            t = []
            for i in y:
                t.append(i[::-1])

        if t == 'XY':
            self.x, self.y = y, x

        self.ShuDu = ShuDu.ShuDu(self.x, self.y)

    def run(self):
        self.ShuDu.begin()
        data = {'data': self.ShuDu.data, 'size': self.ShuDu.size, 'type': self.t}
        self.trigger.emit(data)
